import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import Layout from "../layout/index.vue";
import Home from "../views/home/index.vue";
export const constantRoutes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "login",
    component: () => import("@/views/login/index.vue"),
  },
  {
    path: "/base",
    name: "base",
    redirect: "/home",
    component: Layout,
    children: [
      {
        path: "/home",
        name: "home",
        component: Home,
      },
    ],
  },
  {
    path: "/project",
    name: "project",
    meta: { title: "项目管理" },
    redirect: "/project-manager",
    component: Layout,
    children: [
      {
        path: "/project-manager",
        name: "project-manager",
        component: () => import("@/views/projectManager/index.vue"),
      },
    ],
  },
  {
    path: "/qa",
    name: "qa",
    meta: { title: "问题管理" },
    redirect: "/qa-manager",
    component: Layout,
    children: [
      {
        path: "/qa-manager",
        name: "qa-manager",
        component: () => import("@/views/qaManager/index.vue"),
      },
    ],
  },
  {
    path: "/review",
    name: "review",
    meta: { title: "评审管理" },
    redirect: "/review-manager",
    component: Layout,
    children: [
      {
        path: "/review-manager",
        name: "review-manager",
        component: () => import("@/views/reviewManagement/index.vue"),
      },
    ],
  },
  {
    path: "/user",
    name: "user",
    redirect: "/users",
    component: Layout,
    meta: {
      title: "个人中心",
      icon: "dashboard",
    },
    children: [
      {
        path: "/users",
        name: "users",
        component: () => import("@/views/user/index.vue"),
      },
    ],
  },
  {
    path: "/404",
    name: "err404",
    component: () => import("@/views/errorPage/err404.vue"),
  },
];
const createRouters = () =>
  createRouter({
    history: createWebHashHistory(),
    routes: constantRoutes,
    scrollBehavior(to, from, savedPosition) {
      return {
        el: "#app",
        top: 0,
      };
    },
  });
const router = createRouters();
export function resetRouter() {
  const newRouter = createRouters();
  (router as any).matcher = (newRouter as any).matcher;
}

export default router;
